package com.liuya.base;

import java.io.Serializable;
import java.util.*;

/**
 * @author liuya
 * @date 20160823
 */
public class BaseModel implements Serializable {
    private String id;
    private String name;
    private String pid;
    private String description;
    private Boolean enable;
    private String remark;
    private String createBy;
    private Date createTime;
    private String updateBy;
    private Date updateTime;
    private Collection children = new ArrayList();
    private BaseModel parent;

    /**
     * 0 -> false
     * 1 -> true
     */
    private Boolean isLeaf;

    public Boolean getIsLeaf() {
        return isLeaf;
    }

    public void setIsLeaf(Boolean isLeaf) {
        this.isLeaf = isLeaf;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @return the id
     */
    public String getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(String id) {
        this.id = id;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    /**
     * @return the enable
     */
    public Boolean getEnable() {
        return enable;
    }

    /**
     * @param enable the enable to set
     */
    public void setEnable(Boolean enable) {
        this.enable = enable;
    }

    /**
     * @return the remark
     */
    public String getRemark() {
        return remark;
    }

    /**
     * @param remark the remark to set
     */
    public void setRemark(String remark) {
        this.remark = remark == null ? null : remark.trim();
    }

    /**
     * @return the createBy
     */
    public String getCreateBy() {
        return createBy;
    }

    /**
     * @param createBy the createBy to set
     */
    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @return the updateBy
     */
    public String getUpdateBy() {
        return updateBy;
    }

    /**
     * @param updateBy the updateBy to set
     */
    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    /**
     * @return the updateTime
     */
    public Date getUpdateTime() {
        return updateTime;
    }

    /**
     * @param updateTime the updateTime to set
     */
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Collection getChildren() {
        return children;
    }

    public void setChildren(Collection children) {
        this.children = children;
    }

    public BaseModel getParent() {
        return parent;
    }

    public void setParent(BaseModel parent) {
        this.parent = parent;
    }

    public Collection getAllChildrenNodeIds() {
        Collection nodeIds = new LinkedList();
        if (children != null) {
            for (Iterator iter = children.iterator(); iter.hasNext(); ) {
                BaseModel child = (BaseModel) iter.next();
                nodeIds.add(child.getId());
                getAllChildrenNodeIds(nodeIds, child);
            }
        }

        return nodeIds;
    }

    private void getAllChildrenNodeIds(Collection nodeIds, BaseModel node) {
        Collection thisNodeChildren = node.getChildren();
        if (thisNodeChildren != null) {
            for (Iterator iter = thisNodeChildren.iterator(); iter.hasNext(); ) {
                BaseModel child = (BaseModel) iter.next();
                nodeIds.add(child.getId());
                getAllChildrenNodeIds(nodeIds, child);
            }
        }
    }

}
